package study.spring.transaction.anno;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class JdbcAnnoServiceImpl implements JdbcAnnoService {
	
	private JdbcTemplate template;

	public void insertRuntimeEx(final AnnoEditLink t) {

		String sql = "INSERT INTO tbl_chouti_edit_link (name,img_url,url) VALUES ('5', '/images/image48.png', 'http://www.baidu.com')";
		template.execute(sql);

		throw new RuntimeException();
	}
	
	public void insertCheckEx(final AnnoEditLink t) throws Exception{
		String sql = "INSERT INTO tbl_chouti_edit_link (name,img_url,url) VALUES ('5', '/images/image48.png', 'http://www.baidu.com')";
		template.execute(sql);

		throw new Exception();
	}
	
	@Transactional(noRollbackFor=RuntimeException.class)
	public void insertRuntimeEx() throws Exception{
		String sql = "INSERT INTO tbl_chouti_edit_link (name,img_url,url) VALUES ('5', '/images/image48.png', 'http://www.baidu.com')";
		template.execute(sql);

		throw new RuntimeException();
	}

	// ============================
	public JdbcTemplate getTemplate() {
		return template;
	}

	public void setTemplate(JdbcTemplate template) {
		this.template = template;
	}

}
